<template>
  <div class="yh-layout-box mt-20 x-list" v-if="list && list.length > 0">
    <!-- <router-link class="x-list-more" :to="{ name: 'SearchXorder', params: {} }">
      更多
    </router-link> -->
    <a class="x-list-more" @click="routeToPath('/search/xorder', 'mall')">
      更多
    </a>
      <el-carousel :class="'x-list-items x-list-items'+list.length" trigger="click" height="146px"  :autoplay="true" :interval="5000" arrow="always" indicator-position="none">
        <el-carousel-item v-for="(item, index) in list" :key="index" v-if="index<list.length && index%2==0">
          <!-- <router-link :to="{ name: 'SearchXorderDetail', params: {id: list[index].id} }" class="x-item"> -->
          <a class="x-item" @click="routeToPath('/search/xorderDetail/'+list[index].id, 'mall')">
            <div class="x-pic">
              <img src="@/assets/images/xorder/home-xlist-icon.png">
            </div>
            <div class="x-info">
              <div class="x-head">
                <h3>协议订单</h3>
                <span class="x-read"> <img src="@/assets/images/xorder/home-xlist-read.png"> {{ list[index].readNum }}人已查看</span>
              </div>
              <div class="x-content">
                {{ list[index].templateName }}
              </div>
              <div class="x-foot">
                <span class="x-shop"> <img :src="URL.PIC+list[index].factoryLogo"> {{ list[index].factoryName }}</span>
                <span class="x-date">{{  list[index].createTime.split(' ')[0] }}</span>
              </div>
            </div>
          </a>
          <!-- </router-link> -->

          <!-- <router-link v-if="list[index+1]!=undefined" :to="{ name: 'SearchXorderDetail', params: {id: list[index+1].id} }" class="x-item"> -->
          <a class="x-item" v-if="list[index+1]!=undefined" @click="routeToPath('/search/xorderDetail/'+list[index+1].id, 'mall')">
            <div class="x-pic">
              <img src="@/assets/images/xorder/home-xlist-icon.png">
            </div>
            <div class="x-info">
              <div class="x-head">
                <h3>协议订单</h3>
                <span class="x-read"> <img src="@/assets/images/xorder/home-xlist-read.png"> {{ list[index+1].readNum }}人已查看</span>
              </div>
              <div class="x-content">
                {{ list[index+1].templateName }}
              </div>
              <div class="x-foot">
                <span class="x-shop"> <img :src="URL.PIC+list[index+1].factoryLogo"> {{ list[index+1].factoryName }}</span>
                <span class="x-date">{{  list[index+1].createTime.split(' ')[0] }}</span>
              </div>
            </div>
          </a>
          <!-- </router-link> -->
        </el-carousel-item>
      </el-carousel>

  </div>
</template>

<script>
import { getOpenList } from '@/api/xorder'
export default {

  data() {
    return {
      list: null,
      count: 0,
    }
  },
  created() {
    this.getOpenList();
  },
  methods: {
    getOpenList() {
      getOpenList({
        page: 1,
        size: 6,
      }).then(res=>{
        this.list = res.data.list
        if(res.data!=undefined){
          let len = res.data.list[0].length;
          if(len>0){
            this.count = parseInt(len/2);
          }
          if(res.data.list[0].length%2!=0){
            this.count ++;
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.x-list{
  overflow: hidden;
  margin-top: 30px;
  .x-list-more{
    text-align: right;
    margin-bottom: 10px;
    display: block;
    text-decoration: none;
    color: #999999;
    transition: all .3s;
    &:hover{
      color: #255B8B;
    }
  }
  .x-list-items{
    .x-item{
      float: left;
      padding: 20px;
      width: 550px;
      background-color: #E9EEF3;
      border-radius: 10px;
      transition: all .3s;
      &:hover{
        box-shadow: inset 0 0 24px rgba(0,0,0,0.06)
      }
      .x-pic{
        float: left;
        width: 100px;
        height: 100px;
      }
      .x-info{
        float: left;
        margin-left: 20px;
        width: 430px;
        .x-head{
          overflow: hidden;
          margin-bottom: 24px;
          h3{
            float: left;
            padding: 0;
            font-size: 18px;
            font-weight: 500;
            margin: 0;
            color: #255B8B;
            font-weight: bold;
          }
          .x-read{
            float: right;
            color: #255B8B;
            font-size: 14px;
            img{
              vertical-align: middle;
              margin-top: -4px;
            }
          }
        }
        .x-content{
          color: #333333;
          width: 425px;
          height: 20px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          margin-bottom: 22px;
        }
        .x-foot{
          overflow: hidden;
          color: #888888;
          .x-shop{
            float: left;
            width: 300px;
            overflow: hidden;
            height: 20px;
            display: block;
            text-overflow: ellipsis;
            white-space: nowrap;
            img{
              width: 14px;
              height: 14px;
              overflow: hidden;
              border-radius: 20px;
              vertical-align: middle;
              margin-top: -2px;
              margin-right: 4px;
            }
          }
          .x-date{
            float: right;
          }
        }
      }
    }
    .x-item:nth-child(1){
      margin-right: 20px;
    }
  }
}
</style>

<style lang="scss">
  .x-list{
    .el-carousel__arrow--right{
      right: 0px;
    }
    .el-carousel__arrow--left{
      left: 0px;
    }
    .el-carousel__arrow{
      border-radius: 3px 0 0 3px;
      width: 24px;
    }
  }
  .x-list-items1{
    .el-carousel__arrow{
      display: none;
    }
  }
</style>
